import inspect

# 文件对象
def test__File():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    try:
        from kinyx.file_util import File
        file = File('C:/xxx/test.ext')
        file.print()
        print('md5                  :', file.md5())
    except ValueError as e:
        print(e)


# 文件夹对象
def test__Directory():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    try:
        from kinyx.file_util import Directory
        directory = Directory('C:/xxx/test')
        directory.print()
        print('empty                :', directory.empty())
    except FileNotFoundError as e:
        print(e)


from kinyx.file_util import File
def test__select_file():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    from kinyx.file_util import select_file
    file_path = select_file(
        title       = '...',
        filetypes   = [('MP4', '*.mp4')],
    )
    print('file_path            :', file_path)
    file = File(file_path)
    file.print()
    print('md5                  :', file.md5())


from kinyx.file_util import Directory
def test__select_directory():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    from kinyx.file_util import select_directory
    folder_path = select_directory(
        title       = '...',
    )
    print('folder_path          :', folder_path)
    directory = Directory(folder_path)
    directory.print()
    print('empty                :', directory.empty())


from kinyx.file_util import select_directory
def test__for_directory():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    from kinyx.file_util import for_directory
    folder_path = select_directory()

    def function_if_file(directory, file):
        file.print()
        print('md5                  :', file.md5())

    def function_if_directory(directory, file):
        file.print()
        print('empty                :', file.empty())

    for_directory(
        directory               = folder_path,
        function_if_file        = function_if_file,
        function_if_directory   = function_if_directory,
    )

test__File()
test__Directory()
# test__select_file()
# test__select_directory()
# test__for_directory()